/**
 * @description 设数据角色组编辑弹窗
 * @author 李艳
 */

import React, {Component} from 'react'
import {Form, Input,Modal} from 'antd';
import {cache, checkInputCode, getUserInfo} from "../../../commons/utils/CommonUtils";

const FormItem = Form.Item;

class EditDataRoleGroupModal extends Component {
  constructor(props) {
    super(props);
    this.state = {}
  }

  handleClose = () => {
    this.props.form.resetFields();
  };

  componentDidMount() {
    this.props.onRef(this);
  }

  render() {
    const formItemLayout = {
      labelCol: {
        span: 7
      },
      wrapperCol: {
        span: 14
      },
    };

    const {confirmLoading, modalVisible, handleOk, handleCancel, defaultValue, isAdd} = this.props;
    const {getFieldDecorator} = this.props.form;
    let title = "编辑数据角色组";
    let FormValue = defaultValue;
    if (isAdd) {
      title = "新增数据角色组";
      FormValue = {}
    }
    const {tenantCode = ""} = getUserInfo();
    return (
      <div>
        <Modal title={title}
                       visible={modalVisible}
                       onOk={handleOk}
                       onCancel={handleCancel}
                       width={500}
                       afterClose={this.handleClose}
                       confirmLoading={confirmLoading}
                       maskClosable={false}
        >
          <FormItem
            style={{display: "none"}}
            label="id">
            {getFieldDecorator('id', {
              initialValue: FormValue.id ? FormValue.id : "",
            })(
              <Input/>
            )}
          </FormItem>
          <FormItem
            label={"代码"}
            {...formItemLayout}
          >
            {getFieldDecorator('code', {
              initialValue: FormValue.code ? FormValue.code.substring(FormValue.code.indexOf('-') + 1, FormValue.code.length) : "",
              rules: [{required: true, message: '请填写代码!'},checkInputCode()]
            })(
              <Input addonBefore={`${tenantCode}-`}
                     maxLength={tenantCode ? 20 -tenantCode.split("").length - 1 : 20}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="名称">
            {getFieldDecorator('name', {
              initialValue: FormValue.name ? FormValue.name : "",
              rules: [{required: true, message: '请填写名称!'}]
            })(
              <Input/>
            )}
          </FormItem>
        </Modal>
      </div>
    );
  }
}

EditDataRoleGroupModal = Form.create()(EditDataRoleGroupModal);
export default EditDataRoleGroupModal;
